package com.furongji.education.service.impl;

import com.furongji.education.clients.VodFeignClient;
import com.furongji.education.domain.po.Section;
import com.furongji.education.mapper.SectionMapper;
import com.furongji.education.service.SectionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author furongji
 * @since 2025-05-19
 */
@Service
@RequiredArgsConstructor
public class SectionServiceImpl extends ServiceImpl<SectionMapper, Section> implements SectionService {

    private final VodFeignClient vodFeignClient;

    // TODO 后续改用RabbitMQ
    @Override
    @Transactional
    public boolean removeSectionById(String id) {
        Section section = super.getById(id);
        String videoSourceId = section.getVideoSourceId();
        if (StringUtils.hasText(videoSourceId)) {
            vodFeignClient.removeVideo(videoSourceId);
        }
        super.removeById(id);
        return true;
    }
}
